﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using bdnt_pets_system_Entity;

namespace bdnt_pets_system.Tools
{
    public class HelpTools
    {
        public static Color HtmlToColor(string htmlColr)
        {
            int baseIndex = 1;
            byte a, r, g, b; a = r = g = b = 255;
            if (htmlColr.Length == 9)
            {
                a = Convert.ToByte(htmlColr.Substring(baseIndex, 2), 16);
                baseIndex += 2;
            }
            r = Convert.ToByte(htmlColr.Substring(baseIndex, 2), 16);
            g = Convert.ToByte(htmlColr.Substring(baseIndex += 2, 2), 16);
            b = Convert.ToByte(htmlColr.Substring(baseIndex += 2, 2), 16);
            return Color.FromArgb(a, r, g, b);
        }

        public static List<SimpleObject<int, string>> DistinctList(List<SimpleObject<int, string>> cuLis)
        {
            List<SimpleObject<int, string>> cures = new List<SimpleObject<int, string>>();
            int i = 0;           
            foreach (var item in cuLis)
            {
                if (item.Item1 != i && !string.IsNullOrEmpty(item.Item2))
                {
                    i = item.Item1;
                    cures.Add(item);
                }
            }
            return cures;
        }

        public static List<SimpleObject<string, string>> DistinctList1(List<SimpleObject<string, string>> cuLis)
        {
            List<SimpleObject<string, string>> cures = new List<SimpleObject<string, string>>();
            SimpleObject<string, string> cuo = new SimpleObject<string, string>();
            foreach (var item in cuLis)
            {
                if (item.Item1 == cuo.Item1)
                    continue;
                cures.Add(item);
                cuo = item;
            }
            return cures;

        }

        public static string GetFileSize(long value)
        {
            string size = "0 KB";

            if (value > 0)
            {
                double byteCount = (double)value;

                if (byteCount >= 1073741824)
                    size = String.Format("{0:##.##}", byteCount / 1073741824) + " GB";
                else if (byteCount >= 1048576)
                    size = String.Format("{0:##.##}", byteCount / 1048576) + " MB";
                else if (byteCount >= 1024)
                    size = String.Format("{0:##.##}", byteCount / 1024) + " KB";
                else if (byteCount > 0 && byteCount < 1024)
                    size = "1 KB";    //Bytes are unimportant ;)            

            }

            return size;
        }
    }
}
